package com.wc.alorithm_luogu.P1449;

import java.util.Scanner;
import java.util.Stack;

/**
 * @Author congge
 * @Date 2023/5/14 18:13
 * @description https://www.luogu.com.cn/problem/P1449
 * 后缀表达式(栈问题)
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String s = sc.nextLine();

        // 数字的栈
        Stack<Integer> stack = new Stack<>();
        char[] chs = s.toCharArray();

        int curNumber = 0;

        for (char ch : chs) {
            if (ch >= '0' && ch <= '9') {
                curNumber = curNumber * 10 + (ch - '0');
            } else if (ch == '.') {
                stack.push(curNumber);
                curNumber = 0;
            } else if (ch == '@') {
                break;
                // 运算符，提取两个数计算后的结果再入栈
            } else {
                int b = stack.pop();
                int a = stack.pop();
                int res = 0;
                switch (ch) {
                    case '+': {
                        res = a + b;
                        break;
                    }
                    case '-': {
                        res = a - b;
                        break;
                    }
                    case '*': {
                        res = a * b;
                        break;
                    }
                    case '/': {
                        res = a / b;
                        break;
                    }
                }
                stack.push(res);
            }
        }
        System.out.println(stack.peek());
    }
}
